import './detail.css';
import {connect} from 'react-redux';
import {Link} from 'react-router';
import Panel from './../../elements/Panel'
import {URL, md5Url} from '../../libs/Url';
import {Config} from '../../libs/';
import BreadcrumbNavigation from './../../components/BreadcrumbNavigation';

import {
    fetch,
    fetch_remove,
    enable_delete_btn,
    selectAllItem,
    selectItem,
} from '../../actions';
import {SUBJECT, PAGE_SUBJECT} from './../../actions/subject'
const Title = React.createClass({
    render(){
        return (
            <h1 className="text-center mtop35">{this.props.title}</h1>
        )
    }
});
const Des = React.createClass({
    render(){
        return (
            <p className="text-center auth-row">
                作者： <Link to="#">{this.props.author}</Link> |
                时间：{Moment(this.props.intime).format('YYYY-MM-DD HH:MM:ss')} | 来源：<Link
                to="#">{this.props.source}</Link>
            </p>
        )
    }
});
const Detail = React.createClass({
    componentDidMount(){
        const {dispatch} = this.props;
        dispatch(fetch({url: URL.NEWS_GET, newsid: this.props.params.id}));
        // dispatch(fetch(SUBJECT.NEWS_DETAIL, {newsid: this.props.params.id,url:CONFIG.NEWS_PUSH_CLASS}))
    },
    render(){
        const news = this.props[md5Url.NEWS_GET].news || {};
        news.classList = (news.classList instanceof Array) ? news.classList : ['全部'];
        return (
            <div>
                <BreadcrumbNavigation navs={[
                    {url: Config.MENUS.HOME, label: '首页'},
                    {url: Config.MENUS.NEWS, label: '新闻列表'},
                    {label: '正文'},
                ]}>
                </BreadcrumbNavigation>
                <Panel>
                    <div className="panel-body">
                        <Title {...news}></Title>
                        <Des {...news}/>
                        <div className="abstract"><b>摘要：</b>
                            {news.summary}
                        </div>
                        {
                            news.fileids ? <div className="blog-img-wide">
                                <img src={URL.FUN_UPLOAD_PREVIEW(news.fileids)} alt=""/>
                            </div> : null
                        }
                        <div dangerouslySetInnerHTML={{__html: news.content}}></div>
                        <div className="blog-tags">
                            推送到的班级： {
                            news.classList.map((item, index)=> {
                                return <span key={index}>{item.name}</span>
                            })
                        }
                            {
                                news.classList.length ? null : <span>所有</span>
                            }
                        </div>
                    </div>
                </Panel>
            </div>
        )
    }
})
function select(state) {
    return {
        [md5Url.NEWS_GET]: state.fetchBySubject[md5Url.NEWS_GET],
    }
}
export default connect(select)(Detail)